<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>messageformat_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_i18n_messageformat_test.js.html">messageformat_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2010 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.i18n.MessageFormatTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.i18n.MessageFormatTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.i18n.MessageFormat&#39;);
<a name="line19"></a>goog.require(&#39;goog.i18n.NumberFormatSymbols_hr&#39;);
<a name="line20"></a>goog.require(&#39;goog.i18n.pluralRules&#39;);
<a name="line21"></a>goog.require(&#39;goog.testing.PropertyReplacer&#39;);
<a name="line22"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line23"></a>
<a name="line24"></a>// Testing stubs that autoreset after each test run.
<a name="line25"></a>var stubs = new goog.testing.PropertyReplacer();
<a name="line26"></a>
<a name="line27"></a>function tearDown() {
<a name="line28"></a>  stubs.reset();
<a name="line29"></a>}
<a name="line30"></a>
<a name="line31"></a>function testEmptyPattern() {
<a name="line32"></a>  var fmt = new goog.i18n.MessageFormat(&#39;&#39;);
<a name="line33"></a>  assertEquals(&#39;&#39;, fmt.format({}));
<a name="line34"></a>}
<a name="line35"></a>
<a name="line36"></a>function testMissingLeftCurlyBrace() {
<a name="line37"></a>  var err = assertThrows(function() {
<a name="line38"></a>    new goog.i18n.MessageFormat(&#39;\&#39;\&#39;{}}&#39;);
<a name="line39"></a>  });
<a name="line40"></a>  assertEquals(&#39;Assertion failed: No matching { for }.&#39;, err.message);
<a name="line41"></a>}
<a name="line42"></a>
<a name="line43"></a>function testTooManyLeftCurlyBraces() {
<a name="line44"></a>  var err = assertThrows(function() {
<a name="line45"></a>    new goog.i18n.MessageFormat(&#39;{} {&#39;);
<a name="line46"></a>  });
<a name="line47"></a>  assertEquals(&#39;Assertion failed: There are mismatched { or } in the pattern.&#39;,
<a name="line48"></a>      err.message);
<a name="line49"></a>}
<a name="line50"></a>
<a name="line51"></a>function testSimpleReplacement() {
<a name="line52"></a>  var fmt = new goog.i18n.MessageFormat(&#39;New York in {SEASON} is nice.&#39;);
<a name="line53"></a>  assertEquals(&#39;New York in the Summer is nice.&#39;,
<a name="line54"></a>               fmt.format({&#39;SEASON&#39;: &#39;the Summer&#39;}));
<a name="line55"></a>}
<a name="line56"></a>
<a name="line57"></a>function testSimpleSelect() {
<a name="line58"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{GENDER, select,&#39; +
<a name="line59"></a>      &#39;male {His} &#39; +
<a name="line60"></a>      &#39;female {Her} &#39; +
<a name="line61"></a>      &#39;other {Its}}&#39; +
<a name="line62"></a>      &#39; bicycle is {GENDER, select, male {blue} female {red} other {green}}.&#39;);
<a name="line63"></a>
<a name="line64"></a>  assertEquals(&#39;His bicycle is blue.&#39;, fmt.format({&#39;GENDER&#39;: &#39;male&#39;}));
<a name="line65"></a>  assertEquals(&#39;Her bicycle is red.&#39;, fmt.format({&#39;GENDER&#39;: &#39;female&#39;}));
<a name="line66"></a>  assertEquals(&#39;Its bicycle is green.&#39;, fmt.format({&#39;GENDER&#39;: &#39;other&#39;}));
<a name="line67"></a>  assertEquals(&#39;Its bicycle is green.&#39;, fmt.format({&#39;GENDER&#39;: &#39;whatever&#39;}));
<a name="line68"></a>}
<a name="line69"></a>
<a name="line70"></a>function testSimplePlural() {
<a name="line71"></a>  var fmt = new goog.i18n.MessageFormat(&#39;I see {NUM_PEOPLE, plural, offset:1 &#39; +
<a name="line72"></a>      &#39;=0 {no one at all in {PLACE}.} &#39; +
<a name="line73"></a>      &#39;=1 {{PERSON} in {PLACE}.} &#39; +
<a name="line74"></a>      &#39;one {{PERSON} and one other person in {PLACE}.} &#39; +
<a name="line75"></a>      &#39;other {{PERSON} and # other people in {PLACE}.}}&#39;);
<a name="line76"></a>
<a name="line77"></a>  assertEquals(&#39;I see no one at all in Belgrade.&#39;,
<a name="line78"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 0,
<a name="line79"></a>        &#39;PLACE&#39;: &#39;Belgrade&#39;}));
<a name="line80"></a>  assertEquals(&#39;I see Markus in Berlin.&#39;,
<a name="line81"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 1,
<a name="line82"></a>        &#39;PERSON&#39;: &#39;Markus&#39;,
<a name="line83"></a>        &#39;PLACE&#39;: &#39;Berlin&#39;}));
<a name="line84"></a>  assertEquals(&#39;I see Mark and one other person in Athens.&#39;,
<a name="line85"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 2,
<a name="line86"></a>        &#39;PERSON&#39;: &#39;Mark&#39;,
<a name="line87"></a>        &#39;PLACE&#39;: &#39;Athens&#39;}));
<a name="line88"></a>  assertEquals(&#39;I see Cibu and 99 other people in the cubes.&#39;,
<a name="line89"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 100,
<a name="line90"></a>        &#39;PERSON&#39;: &#39;Cibu&#39;,
<a name="line91"></a>        &#39;PLACE&#39;: &#39;the cubes&#39;}));
<a name="line92"></a>}
<a name="line93"></a>
<a name="line94"></a>function testSimplePluralNoOffset() {
<a name="line95"></a>  var fmt = new goog.i18n.MessageFormat(&#39;I see {NUM_PEOPLE, plural, &#39; +
<a name="line96"></a>      &#39;=0 {no one at all} &#39; +
<a name="line97"></a>      &#39;=1 {{PERSON}} &#39; +
<a name="line98"></a>      &#39;one {{PERSON} and one other person} &#39; +
<a name="line99"></a>      &#39;other {{PERSON} and # other people}} in {PLACE}.&#39;);
<a name="line100"></a>
<a name="line101"></a>  assertEquals(&#39;I see no one at all in Belgrade.&#39;,
<a name="line102"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 0,
<a name="line103"></a>        &#39;PLACE&#39;: &#39;Belgrade&#39;}));
<a name="line104"></a>  assertEquals(&#39;I see Markus in Berlin.&#39;,
<a name="line105"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 1,
<a name="line106"></a>        &#39;PERSON&#39;: &#39;Markus&#39;,
<a name="line107"></a>        &#39;PLACE&#39;: &#39;Berlin&#39;}));
<a name="line108"></a>  assertEquals(&#39;I see Mark and 2 other people in Athens.&#39;,
<a name="line109"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 2,
<a name="line110"></a>        &#39;PERSON&#39;: &#39;Mark&#39;,
<a name="line111"></a>        &#39;PLACE&#39;: &#39;Athens&#39;}));
<a name="line112"></a>  assertEquals(&#39;I see Cibu and 100 other people in the cubes.&#39;,
<a name="line113"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 100,
<a name="line114"></a>        &#39;PERSON&#39;: &#39;Cibu&#39;,
<a name="line115"></a>        &#39;PLACE&#39;: &#39;the cubes&#39;}));
<a name="line116"></a>}
<a name="line117"></a>
<a name="line118"></a>function testSelectNestedInPlural() {
<a name="line119"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{CIRCLES, plural, &#39; +
<a name="line120"></a>      &#39;one {{GENDER, select, &#39; +
<a name="line121"></a>      &#39;  female {{WHO} added you to her circle} &#39; +
<a name="line122"></a>      &#39;  other  {{WHO} added you to his circle}}} &#39; +
<a name="line123"></a>      &#39;other {{GENDER, select, &#39; +
<a name="line124"></a>      &#39;  female {{WHO} added you to her # circles} &#39; +
<a name="line125"></a>      &#39;  other  {{WHO} added you to his # circles}}}}&#39;);
<a name="line126"></a>
<a name="line127"></a>  assertEquals(&#39;Jelena added you to her circle&#39;,
<a name="line128"></a>               fmt.format({&#39;GENDER&#39;: &#39;female&#39;,
<a name="line129"></a>        &#39;WHO&#39;: &#39;Jelena&#39;,
<a name="line130"></a>        &#39;CIRCLES&#39;: 1}));
<a name="line131"></a>  assertEquals(&#39;Milan added you to his 1,234 circles&#39;,
<a name="line132"></a>               fmt.format({&#39;GENDER&#39;: &#39;male&#39;,
<a name="line133"></a>        &#39;WHO&#39;: &#39;Milan&#39;,
<a name="line134"></a>        &#39;CIRCLES&#39;: 1234}));
<a name="line135"></a>}
<a name="line136"></a>
<a name="line137"></a>function testPluralNestedInSelect() {
<a name="line138"></a>  // Added offset just for testing purposes. It doesn&#39;t make sense
<a name="line139"></a>  // to have it otherwise.
<a name="line140"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{GENDER, select, &#39; +
<a name="line141"></a>      &#39;female {{NUM_GROUPS, plural, &#39; +
<a name="line142"></a>      &#39;  one {{WHO} added you to her group} &#39; +
<a name="line143"></a>      &#39;  other {{WHO} added you to her # groups}}} &#39; +
<a name="line144"></a>      &#39;other {{NUM_GROUPS, plural, offset:1&#39; +
<a name="line145"></a>      &#39;  one {{WHO} added you to his group} &#39; +
<a name="line146"></a>      &#39;  other {{WHO} added you to his # groups}}}}&#39;);
<a name="line147"></a>
<a name="line148"></a>  assertEquals(&#39;Jelena added you to her group&#39;,
<a name="line149"></a>               fmt.format({&#39;GENDER&#39;: &#39;female&#39;,
<a name="line150"></a>        &#39;WHO&#39;: &#39;Jelena&#39;,
<a name="line151"></a>        &#39;NUM_GROUPS&#39;: 1}));
<a name="line152"></a>  assertEquals(&#39;Milan added you to his 1,233 groups&#39;,
<a name="line153"></a>               fmt.format({&#39;GENDER&#39;: &#39;male&#39;,
<a name="line154"></a>        &#39;WHO&#39;: &#39;Milan&#39;,
<a name="line155"></a>        &#39;NUM_GROUPS&#39;: 1234}));
<a name="line156"></a>}
<a name="line157"></a>
<a name="line158"></a>function testLiteralOpenCurlyBrace() {
<a name="line159"></a>  var fmt = new goog.i18n.MessageFormat(&quot;Anna&#39;s house&quot; +
<a name="line160"></a>      &quot; has &#39;{0} and # in the roof&#39; and {NUM_COWS} cows.&quot;);
<a name="line161"></a>  assertEquals(&quot;Anna&#39;s house has {0} and # in the roof and 5 cows.&quot;,
<a name="line162"></a>               fmt.format({&#39;NUM_COWS&#39;: &#39;5&#39;}));
<a name="line163"></a>}
<a name="line164"></a>
<a name="line165"></a>function testLiteralClosedCurlyBrace() {
<a name="line166"></a>  var fmt = new goog.i18n.MessageFormat(&quot;Anna&#39;s house&quot; +
<a name="line167"></a>      &quot; has &#39;{&#39;0&#39;} and # in the roof&#39; and {NUM_COWS} cows.&quot;);
<a name="line168"></a>  assertEquals(&quot;Anna&#39;s house has {0} and # in the roof and 5 cows.&quot;,
<a name="line169"></a>               fmt.format({&#39;NUM_COWS&#39;: &#39;5&#39;}));
<a name="line170"></a>}
<a name="line171"></a>
<a name="line172"></a>function testLiteralPoundSign() {
<a name="line173"></a>  var fmt = new goog.i18n.MessageFormat(&quot;Anna&#39;s house&quot; +
<a name="line174"></a>      &quot; has &#39;{0}&#39; and &#39;# in the roof&#39; and {NUM_COWS} cows.&quot;);
<a name="line175"></a>  assertEquals(&quot;Anna&#39;s house has {0} and # in the roof and 5 cows.&quot;,
<a name="line176"></a>               fmt.format({&#39;NUM_COWS&#39;: &#39;5&#39;}));
<a name="line177"></a>}
<a name="line178"></a>
<a name="line179"></a>function testNoLiteralsForSingleQuotes() {
<a name="line180"></a>  var fmt = new goog.i18n.MessageFormat(&quot;Anna&#39;s house&quot; +
<a name="line181"></a>      &quot; &#39;has {NUM_COWS} cows&#39;.&quot;);
<a name="line182"></a>  assertEquals(&quot;Anna&#39;s house &#39;has 5 cows&#39;.&quot;, fmt.format({&#39;NUM_COWS&#39;: &#39;5&#39;}));
<a name="line183"></a>}
<a name="line184"></a>
<a name="line185"></a>function testConsecutiveSingleQuotesAreReplacedWithOneSingleQuote() {
<a name="line186"></a>  var fmt = new goog.i18n.MessageFormat(&quot;Anna&#39;&#39;s house a&#39;{&#39;&#39;&#39;&#39;b&#39;&quot;);
<a name="line187"></a>  assertEquals(&quot;Anna&#39;s house a{&#39;&#39;b&quot;, fmt.format({}));
<a name="line188"></a>}
<a name="line189"></a>
<a name="line190"></a>function testConsecutiveSingleQuotesBeforeSpecialCharDontCreateLiteral() {
<a name="line191"></a>  var fmt = new goog.i18n.MessageFormat(&quot;a&#39;&#39;{NUM_COWS}&#39;b&quot;);
<a name="line192"></a>  assertEquals(&quot;a&#39;5&#39;b&quot;, fmt.format({&#39;NUM_COWS&#39;: &#39;5&#39;}));
<a name="line193"></a>}
<a name="line194"></a>
<a name="line195"></a>function testSerbianSimpleSelect() {
<a name="line196"></a>  stubs.set(goog.i18n.pluralRules, &#39;select&#39;, goog.i18n.pluralRules.beSelect_);
<a name="line197"></a>
<a name="line198"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{GENDER, select, &#39; +
<a name="line199"></a>      &#39;female {Njen} other {Njegov}} bicikl je &#39; +
<a name="line200"></a>      &#39;{GENDER, select, female {crven} other {plav}}.&#39;);
<a name="line201"></a>
<a name="line202"></a>  assertEquals(&#39;Njegov bicikl je plav.&#39;, fmt.format({&#39;GENDER&#39;: &#39;male&#39;}));
<a name="line203"></a>  assertEquals(&#39;Njen bicikl je crven.&#39;, fmt.format({&#39;GENDER&#39;: &#39;female&#39;}));
<a name="line204"></a>}
<a name="line205"></a>
<a name="line206"></a>function testSerbianSimplePlural() {
<a name="line207"></a>  stubs.set(goog.i18n.pluralRules, &#39;select&#39;, goog.i18n.pluralRules.beSelect_);
<a name="line208"></a>
<a name="line209"></a>  var fmt = new goog.i18n.MessageFormat(&#39;Ja {NUM_PEOPLE, plural, offset:1 &#39; +
<a name="line210"></a>      &#39;=0 {ne vidim nikoga} &#39; +
<a name="line211"></a>      &#39;=1 {vidim {PERSON}} &#39; +
<a name="line212"></a>      &#39;one {vidim {PERSON} i jos # osobu} &#39; +
<a name="line213"></a>      &#39;few {vidim {PERSON} i jos # osobe} &#39; +
<a name="line214"></a>      &#39;many {vidim {PERSON} i jos # osoba} &#39; +
<a name="line215"></a>      &#39;other {{PERSON} i jos # osoba}} &#39; +
<a name="line216"></a>      &#39;u {PLACE}.&#39;);
<a name="line217"></a>
<a name="line218"></a>  assertEquals(&#39;Ja ne vidim nikoga u Beogradu.&#39;,
<a name="line219"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 0,
<a name="line220"></a>        &#39;PLACE&#39;: &#39;Beogradu&#39;}));
<a name="line221"></a>  assertEquals(&#39;Ja vidim Markusa u Berlinu.&#39;,
<a name="line222"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 1,
<a name="line223"></a>        &#39;PERSON&#39;: &#39;Markusa&#39;,
<a name="line224"></a>        &#39;PLACE&#39;: &#39;Berlinu&#39;}));
<a name="line225"></a>  assertEquals(&#39;Ja vidim Marka i jos 1 osobu u Atini.&#39;,
<a name="line226"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 2,
<a name="line227"></a>        &#39;PERSON&#39;: &#39;Marka&#39;,
<a name="line228"></a>        &#39;PLACE&#39;: &#39;Atini&#39;}));
<a name="line229"></a>  assertEquals(&#39;Ja vidim Petra i jos 3 osobe u muzeju.&#39;,
<a name="line230"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 4,
<a name="line231"></a>        &#39;PERSON&#39;: &#39;Petra&#39;,
<a name="line232"></a>        &#39;PLACE&#39;: &#39;muzeju&#39;}));
<a name="line233"></a>  assertEquals(&#39;Ja vidim Cibua i jos 99 osoba u bazenu.&#39;,
<a name="line234"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 100,
<a name="line235"></a>        &#39;PERSON&#39;: &#39;Cibua&#39;,
<a name="line236"></a>        &#39;PLACE&#39;: &#39;bazenu&#39;}));
<a name="line237"></a>}
<a name="line238"></a>
<a name="line239"></a>function testSerbianSimplePluralNoOffset() {
<a name="line240"></a>  stubs.set(goog.i18n.pluralRules, &#39;select&#39;, goog.i18n.pluralRules.beSelect_);
<a name="line241"></a>
<a name="line242"></a>  var fmt = new goog.i18n.MessageFormat(&#39;Ja {NUM_PEOPLE, plural, &#39; +
<a name="line243"></a>      &#39;=0 {ne vidim nikoga} &#39; +
<a name="line244"></a>      &#39;=1 {vidim {PERSON}} &#39; +
<a name="line245"></a>      &#39;one {vidim {PERSON} i jos # osobu} &#39; +
<a name="line246"></a>      &#39;few {vidim {PERSON} i jos # osobe} &#39; +
<a name="line247"></a>      &#39;many {vidim {PERSON} i jos # osoba} &#39; +
<a name="line248"></a>      &#39;other {{PERSON} i jos # osoba}} &#39; +
<a name="line249"></a>      &#39;u {PLACE}.&#39;);
<a name="line250"></a>
<a name="line251"></a>  assertEquals(&#39;Ja ne vidim nikoga u Beogradu.&#39;,
<a name="line252"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 0,
<a name="line253"></a>        &#39;PLACE&#39;: &#39;Beogradu&#39;}));
<a name="line254"></a>  assertEquals(&#39;Ja vidim Markusa u Berlinu.&#39;,
<a name="line255"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 1,
<a name="line256"></a>        &#39;PERSON&#39;: &#39;Markusa&#39;,
<a name="line257"></a>        &#39;PLACE&#39;: &#39;Berlinu&#39;}));
<a name="line258"></a>  assertEquals(&#39;Ja vidim Marka i jos 21 osobu u Atini.&#39;,
<a name="line259"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 21,
<a name="line260"></a>        &#39;PERSON&#39;: &#39;Marka&#39;,
<a name="line261"></a>        &#39;PLACE&#39;: &#39;Atini&#39;}));
<a name="line262"></a>  assertEquals(&#39;Ja vidim Petra i jos 3 osobe u muzeju.&#39;,
<a name="line263"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 3,
<a name="line264"></a>        &#39;PERSON&#39;: &#39;Petra&#39;,
<a name="line265"></a>        &#39;PLACE&#39;: &#39;muzeju&#39;}));
<a name="line266"></a>  assertEquals(&#39;Ja vidim Cibua i jos 100 osoba u bazenu.&#39;,
<a name="line267"></a>               fmt.format({&#39;NUM_PEOPLE&#39;: 100,
<a name="line268"></a>        &#39;PERSON&#39;: &#39;Cibua&#39;,
<a name="line269"></a>        &#39;PLACE&#39;: &#39;bazenu&#39;}));
<a name="line270"></a>}
<a name="line271"></a>
<a name="line272"></a>function testSerbianSelectNestedInPlural() {
<a name="line273"></a>  stubs.set(goog.i18n.pluralRules, &#39;select&#39;, goog.i18n.pluralRules.beSelect_);
<a name="line274"></a>  stubs.set(goog.i18n, &#39;NumberFormatSymbols&#39;, goog.i18n.NumberFormatSymbols_hr);
<a name="line275"></a>
<a name="line276"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{CIRCLES, plural, &#39; +
<a name="line277"></a>      &#39;one {{GENDER, select, &#39; +
<a name="line278"></a>      &#39;  female {{WHO} vas je dodala u njen # kruzok} &#39; +
<a name="line279"></a>      &#39;  other  {{WHO} vas je dodao u njegov # kruzok}}} &#39; +
<a name="line280"></a>      &#39;few {{GENDER, select, &#39; +
<a name="line281"></a>      &#39;  female {{WHO} vas je dodala u njena # kruzoka} &#39; +
<a name="line282"></a>      &#39;  other  {{WHO} vas je dodao u njegova # kruzoka}}} &#39; +
<a name="line283"></a>      &#39;many {{GENDER, select, &#39; +
<a name="line284"></a>      &#39;  female {{WHO} vas je dodala u njenih # kruzoka} &#39; +
<a name="line285"></a>      &#39;  other  {{WHO} vas je dodao u njegovih # kruzoka}}} &#39; +
<a name="line286"></a>      &#39;other {{GENDER, select, &#39; +
<a name="line287"></a>      &#39;  female {{WHO} vas je dodala u njenih # kruzoka} &#39; +
<a name="line288"></a>      &#39;  other  {{WHO} vas je dodao u njegovih # kruzoka}}}}&#39;);
<a name="line289"></a>
<a name="line290"></a>  assertEquals(&#39;Jelena vas je dodala u njen 21 kruzok&#39;,
<a name="line291"></a>               fmt.format({&#39;GENDER&#39;: &#39;female&#39;,
<a name="line292"></a>        &#39;WHO&#39;: &#39;Jelena&#39;,
<a name="line293"></a>        &#39;CIRCLES&#39;: 21}));
<a name="line294"></a>  assertEquals(&#39;Jelena vas je dodala u njena 3 kruzoka&#39;,
<a name="line295"></a>               fmt.format({&#39;GENDER&#39;: &#39;female&#39;,
<a name="line296"></a>        &#39;WHO&#39;: &#39;Jelena&#39;,
<a name="line297"></a>        &#39;CIRCLES&#39;: 3}));
<a name="line298"></a>  assertEquals(&#39;Jelena vas je dodala u njenih 5 kruzoka&#39;,
<a name="line299"></a>               fmt.format({&#39;GENDER&#39;: &#39;female&#39;,
<a name="line300"></a>        &#39;WHO&#39;: &#39;Jelena&#39;,
<a name="line301"></a>        &#39;CIRCLES&#39;: 5}));
<a name="line302"></a>  assertEquals(&#39;Milan vas je dodao u njegovih 1.235 kruzoka&#39;,
<a name="line303"></a>               fmt.format({&#39;GENDER&#39;: &#39;male&#39;,
<a name="line304"></a>        &#39;WHO&#39;: &#39;Milan&#39;,
<a name="line305"></a>        &#39;CIRCLES&#39;: 1235}));
<a name="line306"></a>}
<a name="line307"></a>
<a name="line308"></a>function testFallbackToOtherOptionInPlurals() {
<a name="line309"></a>  // Use Arabic plural rules since they have all six cases.
<a name="line310"></a>  // Only locale and numbers matter, the actual language of the message
<a name="line311"></a>  // does not.
<a name="line312"></a>  stubs.set(goog.i18n.pluralRules, &#39;select&#39;, goog.i18n.pluralRules.arSelect_);
<a name="line313"></a>
<a name="line314"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{NUM_MINUTES, plural, &#39; +
<a name="line315"></a>      &#39;other {# minutes}}&#39;);
<a name="line316"></a>
<a name="line317"></a>  // These numbers exercise all cases for the arabic plural rules.
<a name="line318"></a>  assertEquals(&#39;0 minutes&#39;, fmt.format({&#39;NUM_MINUTES&#39;: 0}));
<a name="line319"></a>  assertEquals(&#39;1 minutes&#39;, fmt.format({&#39;NUM_MINUTES&#39;: 1}));
<a name="line320"></a>  assertEquals(&#39;2 minutes&#39;, fmt.format({&#39;NUM_MINUTES&#39;: 2}));
<a name="line321"></a>  assertEquals(&#39;3 minutes&#39;, fmt.format({&#39;NUM_MINUTES&#39;: 3}));
<a name="line322"></a>  assertEquals(&#39;11 minutes&#39;, fmt.format({&#39;NUM_MINUTES&#39;: 11}));
<a name="line323"></a>  assertEquals(&#39;1.5 minutes&#39;, fmt.format({&#39;NUM_MINUTES&#39;: 1.5}));
<a name="line324"></a>}
<a name="line325"></a>
<a name="line326"></a>function testPoundShowsNumberMinusOffsetInAllCases() {
<a name="line327"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{SOME_NUM, plural, offset:1 &#39; +
<a name="line328"></a>      &#39;=0 {#} =1 {#} =2 {#}one {#} other {#}}&#39;);
<a name="line329"></a>
<a name="line330"></a>  assertEquals(&#39;-1&#39;, fmt.format({&#39;SOME_NUM&#39;: &#39;0&#39;}));
<a name="line331"></a>  assertEquals(&#39;0&#39;, fmt.format({&#39;SOME_NUM&#39;: &#39;1&#39;}));
<a name="line332"></a>  assertEquals(&#39;1&#39;, fmt.format({&#39;SOME_NUM&#39;: &#39;2&#39;}));
<a name="line333"></a>  assertEquals(&#39;20&#39;, fmt.format({&#39;SOME_NUM&#39;: &#39;21&#39;}));
<a name="line334"></a>}
<a name="line335"></a>
<a name="line336"></a>function testSpecialCharactersInParamaterDontChangeFormat() {
<a name="line337"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{SOME_NUM, plural,&#39; +
<a name="line338"></a>      &#39;other {# {GROUP}}}&#39;);
<a name="line339"></a>
<a name="line340"></a>  // Test pound sign.
<a name="line341"></a>  assertEquals(&#39;10 group#1&#39;,
<a name="line342"></a>               fmt.format({&#39;SOME_NUM&#39;: &#39;10&#39;, &#39;GROUP&#39;: &#39;group#1&#39;}));
<a name="line343"></a>  // Test other special characters in parameters, like { and }.
<a name="line344"></a>  assertEquals(&#39;10 } {&#39;, fmt.format({&#39;SOME_NUM&#39;: &#39;10&#39;, &#39;GROUP&#39;: &#39;} {&#39;}));
<a name="line345"></a>}
<a name="line346"></a>
<a name="line347"></a>function testMissingOrInvalidPluralParameter() {
<a name="line348"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{SOME_NUM, plural,&#39; +
<a name="line349"></a>      &#39;other {result}}&#39;);
<a name="line350"></a>
<a name="line351"></a>  // Key name doesn&#39;t match A != SOME_NUM.
<a name="line352"></a>  assertEquals(&#39;Undefined or invalid parameter - SOME_NUM&#39;,
<a name="line353"></a>               fmt.format({A: &#39;10&#39;}));
<a name="line354"></a>
<a name="line355"></a>  // Value is not a number.
<a name="line356"></a>  assertEquals(&#39;Undefined or invalid parameter - SOME_NUM&#39;,
<a name="line357"></a>               fmt.format({&#39;SOME_NUM&#39;: &#39;Value&#39;}));
<a name="line358"></a>}
<a name="line359"></a>
<a name="line360"></a>function testMissingSelectParameter() {
<a name="line361"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{GENDER, select,&#39; +
<a name="line362"></a>      &#39;other {result}}&#39;);
<a name="line363"></a>
<a name="line364"></a>  // Key name doesn&#39;t match A != GENDER.
<a name="line365"></a>  assertEquals(&#39;Undefined parameter - GENDER&#39;,
<a name="line366"></a>               fmt.format({A: &#39;female&#39;}));
<a name="line367"></a>}
<a name="line368"></a>
<a name="line369"></a>function testMissingSimplePlaceholder() {
<a name="line370"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{result}&#39;);
<a name="line371"></a>
<a name="line372"></a>  // Key name doesn&#39;t match A != result.
<a name="line373"></a>  assertEquals(&#39;Undefined parameter - result&#39;,
<a name="line374"></a>               fmt.format({A: &#39;none&#39;}));
<a name="line375"></a>}
<a name="line376"></a>
<a name="line377"></a>function testPluralWithIgnorePound() {
<a name="line378"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{SOME_NUM, plural,&#39; +
<a name="line379"></a>      &#39;other {# {GROUP}}}&#39;);
<a name="line380"></a>
<a name="line381"></a>  // Test pound sign.
<a name="line382"></a>  assertEquals(&#39;# group#1&#39;,
<a name="line383"></a>               fmt.formatIgnoringPound({&#39;SOME_NUM&#39;: &#39;10&#39;, &#39;GROUP&#39;: &#39;group#1&#39;}));
<a name="line384"></a>  // Test other special characters in parameters, like { and }.
<a name="line385"></a>  assertEquals(&#39;# } {&#39;,
<a name="line386"></a>      fmt.formatIgnoringPound({&#39;SOME_NUM&#39;: &#39;10&#39;, &#39;GROUP&#39;: &#39;} {&#39;}));
<a name="line387"></a>}
<a name="line388"></a>
<a name="line389"></a>function testSimplePluralWithIgnorePound() {
<a name="line390"></a>  var fmt = new goog.i18n.MessageFormat(
<a name="line391"></a>      &#39;I see {NUM_PEOPLE, plural, offset:1 &#39; +
<a name="line392"></a>      &#39;=0 {no one at all in {PLACE}.} &#39; +
<a name="line393"></a>      &#39;=1 {{PERSON} in {PLACE}.} &#39; +
<a name="line394"></a>      &#39;one {{PERSON} and one other person in {PLACE}.} &#39; +
<a name="line395"></a>      &#39;other {{PERSON} and # other people in {PLACE}.}}&#39;);
<a name="line396"></a>
<a name="line397"></a>  assertEquals(&#39;I see Cibu and # other people in the cubes.&#39;,
<a name="line398"></a>               fmt.formatIgnoringPound({&#39;NUM_PEOPLE&#39;: 100,
<a name="line399"></a>        &#39;PERSON&#39;: &#39;Cibu&#39;,
<a name="line400"></a>        &#39;PLACE&#39;: &#39;the cubes&#39;}));
<a name="line401"></a>}
<a name="line402"></a>
<a name="line403"></a>function testSimpleOrdinal() {
<a name="line404"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{NUM_FLOOR, selectordinal, &#39; +
<a name="line405"></a>      &#39;one {Take the elevator to the #st floor.}&#39; +
<a name="line406"></a>      &#39;two {Take the elevator to the #nd floor.}&#39; +
<a name="line407"></a>      &#39;few {Take the elevator to the #rd floor.}&#39; +
<a name="line408"></a>      &#39;other {Take the elevator to the #th floor.}}&#39;);
<a name="line409"></a>
<a name="line410"></a>  assertEquals(&#39;Take the elevator to the 1st floor.&#39;,
<a name="line411"></a>               fmt.format({&#39;NUM_FLOOR&#39;: 1}));
<a name="line412"></a>  assertEquals(&#39;Take the elevator to the 2nd floor.&#39;,
<a name="line413"></a>               fmt.format({&#39;NUM_FLOOR&#39;: 2}));
<a name="line414"></a>  assertEquals(&#39;Take the elevator to the 3rd floor.&#39;,
<a name="line415"></a>               fmt.format({&#39;NUM_FLOOR&#39;: 3}));
<a name="line416"></a>  assertEquals(&#39;Take the elevator to the 4th floor.&#39;,
<a name="line417"></a>               fmt.format({&#39;NUM_FLOOR&#39;: 4}));
<a name="line418"></a>  assertEquals(&#39;Take the elevator to the 23rd floor.&#39;,
<a name="line419"></a>               fmt.format({&#39;NUM_FLOOR&#39;: 23}));
<a name="line420"></a>  // Esoteric example.
<a name="line421"></a>  assertEquals(&#39;Take the elevator to the 0th floor.&#39;,
<a name="line422"></a>               fmt.format({&#39;NUM_FLOOR&#39;: 0}));
<a name="line423"></a>}
<a name="line424"></a>
<a name="line425"></a>function testOrdinalWithNegativeValue() {
<a name="line426"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{NUM_FLOOR, selectordinal, &#39; +
<a name="line427"></a>      &#39;one {Take the elevator to the #st floor.}&#39; +
<a name="line428"></a>      &#39;two {Take the elevator to the #nd floor.}&#39; +
<a name="line429"></a>      &#39;few {Take the elevator to the #rd floor.}&#39; +
<a name="line430"></a>      &#39;other {Take the elevator to the #th floor.}}&#39;);
<a name="line431"></a>
<a name="line432"></a>  try {
<a name="line433"></a>    fmt.format({&#39;NUM_FLOOR&#39;: -2});
<a name="line434"></a>  } catch (e) {
<a name="line435"></a>    assertEquals(&#39;Assertion failed: Argument index smaller than offset.&#39;,
<a name="line436"></a>                 e.message);
<a name="line437"></a>    return;
<a name="line438"></a>  }
<a name="line439"></a>  fail(&#39;Expected an error to be thrown&#39;);
<a name="line440"></a>}
<a name="line441"></a>
<a name="line442"></a>function testSimpleOrdinalWithIgnorePound() {
<a name="line443"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{NUM_FLOOR, selectordinal, &#39; +
<a name="line444"></a>      &#39;one {Take the elevator to the #st floor.}&#39; +
<a name="line445"></a>      &#39;two {Take the elevator to the #nd floor.}&#39; +
<a name="line446"></a>      &#39;few {Take the elevator to the #rd floor.}&#39; +
<a name="line447"></a>      &#39;other {Take the elevator to the #th floor.}}&#39;);
<a name="line448"></a>
<a name="line449"></a>  assertEquals(&#39;Take the elevator to the #th floor.&#39;,
<a name="line450"></a>               fmt.formatIgnoringPound({&#39;NUM_FLOOR&#39;: 100}));
<a name="line451"></a>}
<a name="line452"></a>
<a name="line453"></a>function testMissingOrInvalidOrdinalParameter() {
<a name="line454"></a>  var fmt = new goog.i18n.MessageFormat(&#39;{SOME_NUM, selectordinal,&#39; +
<a name="line455"></a>      &#39;other {result}}&#39;);
<a name="line456"></a>
<a name="line457"></a>  // Key name doesn&#39;t match A != SOME_NUM.
<a name="line458"></a>  assertEquals(&#39;Undefined or invalid parameter - SOME_NUM&#39;,
<a name="line459"></a>               fmt.format({A: &#39;10&#39;}));
<a name="line460"></a>
<a name="line461"></a>  // Value is not a number.
<a name="line462"></a>  assertEquals(&#39;Undefined or invalid parameter - SOME_NUM&#39;,
<a name="line463"></a>               fmt.format({&#39;SOME_NUM&#39;: &#39;Value&#39;}));
<a name="line464"></a>}
</pre>


</body>
</html>
